package org.example.rabbitmq.service;

import cn.hutool.core.lang.UUID;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author 小杰_cc
 * @version 1.0
 */
@Component
public class RabbitService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    // 发送消息
    public <T> void sendMessage(String exchange, String routingKey,T message){
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString(true));
        rabbitTemplate.convertAndSend(exchange, routingKey, message, correlationData);
    }
}
